package io.github.mosiki.web.controller;

import io.github.mosiki.entity.User;
import io.github.mosiki.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/{userId}")
    @ResponseBody
    public ModelAndView userInfo(@PathVariable Integer userId) {
        User user = userService.findById(userId);
        ModelAndView view = new ModelAndView("user/userinfo");
        view.addObject("user", user);
        return view;
    }
}
